# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=qtpy
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.3.1
pkgrel=2
pkgdesc='Provides an uniform layer to support PyQt5, PyQt4 and PySide with a single codebase (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://github.com/spyder-ide/qtpy/"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-packaging")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5: Qt5 Python bindings"
            "${MINGW_PACKAGE_PREFIX}-pyside2: PySide Qt5 Python bindings")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("$_realname-${pkgver}.tar.gz::https://github.com/spyder-ide/${_realname}/archive/v${pkgver}.tar.gz"
        001-restore-qtwebkit-support.patch)
sha256sums=('8121e8cdc09f927823b627c02bacabb81982024250eb65997032a19d5a10f3cd'
            '250dc43798fd337bc00e71152478676450f8661824cbfd49d6292f3b57bf53c2')

prepare() {
  cd "$srcdir"/${_realname}-${pkgver}
  patch -p1 -i "$srcdir"/001-restore-qtwebkit-support.patch

  cd "$srcdir"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${_f}"
  done

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
